
#delimit;

set more off;

capture log close;


drop _all;

local t2="specify here the folder path where the data are stored";
local t1="specify here the folder path where you want the output data to be stored";


**This do-file allows you to replicate the results in the bottom panel of Table 4 (results for the longitudinal sample);


log using `t1'sampleFRB_w1w2_ext_cross06_w2rel231_w1rel231_long_wlag.log, replace;
drop _all;

set mem 600m;

use `t2'w1rel231_w2rel231_ext; 
*Panel;
sort mergeid wave;




*I classify individuals depending on number of waves;
egen nwave=sum(wave), by (mergeid);
sort mergeid wave;


gen tipo=1 if nwave==1; 
*S�lo en 2004;
replace tipo=3 if nwave==3; 
*En ambas olas;
replace tipo=2 if nwave==2 ;
*drop if mergeid==mergeid[_n-1] & wave==wave[_n-1]+1;




forvalues c=11(1)20{;

           
          display "country==`c'";
         tab tipo if  country==`c';
          
         
             };
tab tipo if country==23;

tab country tipo;
*Longitudinals are in both waves;

tab wave;
encode mergeid, gen(mergeid1);
xtset mergeid1 wave, delta(1);
**I just keep longitudinal observations;
keep if tipo==3;



gen gender1= gender;
tab gender1 if wave==1;
tab gender1 if wave==2;

gen midage=(age>=50 & age<=60);
tab midage if gender1==1;
tab midage if gender1==2;

drop if midage==0 & wave==2;
egen mwave=sum(wave), by (mergeid1);
sort mergeid1 wave;
drop if mwave!=3;
tab country wave;


*Natural parents alive;

*We compute whether they have father/mother;



drop if wave==1 & ((dn026_1==-2) | (dn026_2==-2));
drop if wave==2 & ((dn026_1==-2) | (dn026_2==-2));
drop mwave;
egen mwave=sum(wave), by (mergeid1);
sort mergeid1 wave;
drop if mwave!=3;
tab country wave;

gen mother=1 if (dn026_1==1);
replace mother=0 if dn026_1==5 | dn026_1==-1;
replace mother=1 if wave==1 & dn026_1==. & ((cvid==1 & relrpers2==5 & ppgender==2) | (cvid==2 & relrpers2==6 & ppgender==2)
| (cvid==1 & relrpers2b==5 & ppgender2==2) | (cvid==2 & relrpers2b==6  & ppgender2==2)); 
replace mother=1 if wave==2 & dn026_1==. & ((cvid==1 & relrpers2==5 & ppgender==2) | (cvid==2 & relrpers2==6 & ppgender==2)
| (cvid==1 & relrpers2b==5 & ppgender2==2) | (cvid==2 & relrpers2b==6  & ppgender2==2)); 

gen father=1 if (dn026_2==1);
replace father=0 if (dn026_2==5) | dn026_2==-1;
replace father=1 if wave==1 & dn026_2==. & ((cvid==1 & relrpers2==5 & ppgender==1) | (cvid==2 & relrpers2==6 & ppgender==1)
| (cvid==1 & relrpers2b==5 & ppgender2==1) | (cvid==2 & relrpers2b==6  & ppgender2==1)); 
replace father=1 if wave==2 & dn026_2==. & ((cvid==1 & relrpers2==5 & ppgender==1) | (cvid==2 & relrpers2==6 & ppgender==1)
| (cvid==1 & relrpers2b==5 & ppgender2==1) | (cvid==2 & relrpers2b==6  & ppgender2==1)); 

gen lmother=L.mother if tipo==3 & wave==2 & mergeid1==mergeid1[_n-1];
gen ldn026_1=L.dn026_1 if tipo==3 & wave==2 & mergeid1==mergeid1[_n-1];
gen lfather=L.father if tipo==3 & wave==2 & mergeid1==mergeid1[_n-1];
gen ldn026_2=L.dn026_2 if tipo==3 & wave==2 & mergeid1==mergeid1[_n-1];
gen lep005_=L.ep005_ if tipo==3 & wave==2 & mergeid1==mergeid1[_n-1];
gen lep011_1=L.ep011_1 if tipo==3 & wave==2 & mergeid1==mergeid1[_n-1];
gen lep009_1=L.ep009_1 if tipo==3 & wave==2 & mergeid1==mergeid1[_n-1];
gen lep012_1=L.ep012_1 if tipo==3 & wave==2 & mergeid1==mergeid1[_n-1];
gen lisced_r=L.isced_r if tipo==3 & wave==2 & mergeid1==mergeid1[_n-1];

**Missing info;
drop if (mother==. | father==.) & wave==1;
drop mwave;
egen mwave=sum(wave), by (mergeid1);
sort mergeid1 wave;
drop if mwave!=3;
drop mwave;

**Missing info;
replace mother=0 if mother==. & ldn026_1==5 & wave==2;
*Missings in W2 because they reported in W1 that they did not have parents alive;
replace father=0 if father==. & ldn026_2==5 & wave==2;

drop if mother==. & ldn026_1!=5 & wave==2 & tipo==3; 
drop if mother==. & wave==2 & tipo!=3; 
drop if father==. & ldn026_2!=5 & wave==2 & tipo==3;
drop if father==. & wave==2 & tipo!=3; 
egen mwave=sum(wave), by (mergeid1);
sort mergeid1 wave;
drop if mwave!=3;
drop mwave;

gen nchild2=nchild if wave==1;
replace nchild2=nchild2[_n-1] if wave==2 & tipo==3;
replace nchild2=ch001 if wave==2 & tipo!=3;

gen dn014_b=dn014_ if wave==1;
replace dn014_b=dn014_ if wave==2;
replace dn014_b=dn014_[_n-1] if wave==2 & tipo==3 & mergeid1==mergeid1[_n-1] & dn014_==.;


*Select women aged between 50 and 60 in the second wave;
drop if gender==1;
drop if midage==0 & wave==2;
egen mwave=sum(wave), by (mergeid1);
sort mergeid1 wave;
drop if mwave!=3;
drop mwave;


*Age father/mother;
gen mage=dn028_1;
replace mage=ppage if dn026_1==. & mother==1;
replace mage=ppage2 if dn026_1==. & mother==1 & ppage==0;

gen fage=dn028_2;
replace fage=ppage if dn026_2==. & father==1;
replace fage=ppage2 if dn026_2==. & father==1 & ppage==0;

*Health status father/mother;
gen mhealth=dn033_1;
replace mhealth=pphealth if dn026_1==. & mother==1;
replace mhealth=pphealth2 if dn026_1==. & mother==1 & pphealth==0;
replace mhealth=0 if mother==0;


gen fhealth=dn033_2;
replace fhealth=pphealth if dn026_2==. & father==1;
replace fhealth=pphealth2 if dn026_2==. & father==1 & pphealth==0;
replace fhealth=0 if father==0;

drop if mhealth==-1 | mhealth==-2 | fhealth==-1 | fhealth==-2 | mhealth==. | fhealth==.;
egen mwave=sum(wave), by (mergeid1);
sort mergeid1 wave;
drop if mwave!=3;
tab country wave;
drop mwave;

*Rescaling of US (wave2) and UE (wave1) versions of parental health;
gen mhealth2=1 if mhealth==1 & wave==1;
replace mhealth2=2 if mhealth==2 & wave==1;
replace mhealth2=3 if mhealth==3 & wave==1;
replace mhealth2=4 if (mhealth==4 | mhealth==5) & wave==1;
replace mhealth2=1 if (mhealth==1 | mhealth==2) & wave==2;
replace mhealth2=2 if mhealth==3 & wave==2;
replace mhealth2=3 if mhealth==4 & wave==2;
replace mhealth2=4 if mhealth==5 & wave==2;
replace mhealth2=0 if mhealth==0;

gen fhealth2=1 if fhealth==1 & wave==1;
replace fhealth2=2 if fhealth==2 & wave==1;
replace fhealth2=3 if fhealth==3 & wave==1;
replace fhealth2=4 if (fhealth==4 | fhealth==5) & wave==1;
replace fhealth2=1 if (fhealth==1 | fhealth==2) & wave==2;
replace fhealth2=2 if fhealth==3 & wave==2;
replace fhealth2=3 if fhealth==4 & wave==2;
replace fhealth2=4 if fhealth==5 & wave==2;
replace fhealth2=0 if fhealth==0;

drop phealth;
gen phealth=mhealth2 if (mother==1 & father==0);
replace phealth=fhealth2 if (mother==0 & father==1);
replace phealth=mhealth2 if (mother==1 & father==1) & mhealth2>fhealth2;
replace phealth=fhealth2 if (mother==1 & father==1) & mhealth2<fhealth2;
replace phealth=fhealth2 if (mother==1 & father==1) & mhealth2==fhealth2;
replace phealth=0 if mother==0 & father==0;


gen parent=(mother==1 | father==1);
gen parent1=(dn026_1==1 | dn026_2==1); 
gen nparent=2 if mother==1 & father==1;
replace nparent=0 if mother==0 & father==0;
replace nparent=1 if nparent==.;

gen lparent=L.parent if wave==2 & tipo==3 & mergeid1==mergeid1[_n-1];
gen lnparent=L.nparent if wave==2 & tipo==3 & mergeid1==mergeid1[_n-1];

**Drop if they do not have parents;
drop if parent==0;
egen mwave=sum(wave), by (mergeid1);
sort mergeid1 wave;
drop if mwave!=3;
tab country wave;




*Caregiving;
drop if (sp008==-1 | sp008==-2 | sp008==.);
drop if (sp018==-1 | sp018==-2);
drop if (sp009_1==-1 | sp009_1==-2) | (sp009_2==-1 | sp009_2==-2) | (sp009_3==-1 | sp009_3==-2);
drop if (sp011_1==-1 | sp011_1==-2) | (sp011_2==-1 | sp011_2==-2) | (sp011_3==-1 | sp011_3==-2);
*drop if sp019_1==-2 | sp019_2==-2 | sp019_3==-2;
*drop if sp019_1==-1 | sp019_2==-1 | sp019_3==-1;

*drop if sp019drf==1;
*drop if sp019ddk==1;
drop mwave;
egen mwave=sum(wave), by (mergeid1);
sort mergeid1 wave;
drop if mwave!=3;

*Caregiving to parents outside the HH;
gen carerpo=(( sp009_1==2 | sp009_1==3));
replace carerpo=1 if (( sp009_2==2 | sp009_2==3) );
replace carerpo=1 if (( sp009_3==2 | sp009_3==3) );


*Caregiving to parents inside the HH;
gen carerpi=(( sp019d2==1 | sp019d3==1) & wave==1);
replace  carerpi=((sp019d2==1 | sp019d3==1) & wave==2);
gen carerp=(carerpo==1 | carerpi==1);

*Intensive Caregiving to parents;
gen atweek1=1 if carerpi==1; 
replace atweek1=1 if (sp008==1  & (sp009_1==2 | sp009_1==3) & (sp011_1==2 | sp011_1==1));
replace atweek1=1 if (sp008==1  & (sp009_2==2 | sp009_2==3) & (sp011_2==2 | sp011_2==1));
replace atweek1=1 if (sp008==1  & (sp009_3==2 | sp009_3==3) & (sp011_3==2 | sp011_3==1));
replace atweek1=0 if atweek1==.;

gen daily=1 if carerpi==1; 
replace daily=1 if (sp008==1  & (sp009_1==2 | sp009_1==3) & ( sp011_1==1));
replace daily=1 if (sp008==1  & (sp009_2==2 | sp009_2==3) & ( sp011_2==1));
replace daily=1 if (sp008==1  & (sp009_3==2 | sp009_3==3) & ( sp011_3==1));
replace daily=0 if daily==.;

*Less than intensive;
gen lsweek1=(carerp==1 & atweek1==0);


gen lphealth=L.phealth if wave==2 & tipo==3 & mergeid1==mergeid1[_n-1];
gen latweek1=L.atweek1 if wave==2 & tipo==3 & mergeid1==mergeid1[_n-1];
gen ldaily=L.daily if wave==2 & tipo==3;



*Employment. Hours of work; *Mirar lo de los don't know y refusals;

drop if (ep005_==. | ep005_==-1 | ep005_==-2); 
*Missing values in Nursing homes;
*drop if (ep002_==-2 | ep002_==-1) & wave==2;
drop mwave;
egen mwave=sum(wave), by (mergeid1);
sort mergeid1 wave;
drop if mwave!=3;

gen ep013b=ep013_ if wave==2;
replace ep013b=0 if ep013b==. & wave==2;
gen worker=1 if ep013b>0 & wave==2; 
replace worker=0 if ep005_!=2 & ep125!=1 & wave==2; 
replace worker=0 if (worker==.) & wave==2;

**Definition of worker;
gen worker1=(ep005_==2 );
gen worker2=(ep005_==2 | ep002_==1);
gen lworker1=(lep005_==2);

*Grouping;
gen group=1 if (country==13 | country==14 | country==18);
replace group=2 if (country==11 | country==12 | country==17 | country==20 | country==23);
replace group=3 if (country==15 | country==16 | country==19);


tab group gender1 if wave==2;


*An�lisis;
tab country if gender1==2 & wave==1;



gen ivphealth=(phealth==4);
gen livphealth=(lphealth==4);
gen ivphealthg=(phealth==1 | phealth==2);
gen ivphealthf=(phealth==3);



**Controls;
gen age5055=(age>=50 & age<=55);
gen age5660=(age>=56 & age<=60);
drop if age<0;
gen age1=age/10;
gen age12=age1^2;

**Education dummies;
gen educ1=(edu==0 | edu==1);
gen educ2=(edu==2);
gen educ3=(edu==3);
gen educ4=(edu==4 | edu==5 | edu==6);
drop if edu==97;



drop if (ph003==-2 | ph003==-1) & wave==2;
gen spheuvg=((ph003==1 | ph003==2 | ph003==3) & wave==2);
gen spheuf=(ph003==4 & wave==2);
gen spheub=(ph003==5 & wave==2);
gen spheufb=((spheuf==1 | spheub==1) & wave==2);
gen spheuvg2=((ph003==1 | ph003==2) & wave==2);
gen spheug=(ph003==3 & wave==2);

gen austria=(country==11);
gen germany=(country==12);
gen sweden=(country==13);
gen netherlands=(country==14);
gen spain=(country==15);
gen italy=(country==16);
gen france=(country==17);
gen denmark=(country==18);
gen greece=(country==19);
gen switz=(country==20);
gen belgium=(country==23);

gen group1=(group==1);
gen group2=(group==2);
gen group3=(group==3);
gen married=(dn014_b==1 | dn014_b==2); 
gen nli=(hgtincv-ydipv-yindv)/(pppx2005*1000);


gen sisters=dn037;
replace sisters=0 if (dn037==. | dn037==0 | dn037==-1);
gen brothers=dn036;
replace brothers=0 if (dn036==. | dn036==0 | dn036==-1);

drop if (sisters==-2 | brothers==-2) & wave==2;
drop if nchild2==. & wave==2;


**Hours of care to elderly parents;
gen hours_care1=sp012_1*7 if sp011_1==1;
replace hours_care1=sp012_1 if sp011_1==2;
replace hours_care1=sp012_1/(52/12) if sp011_1==3;
replace hours_care1=sp012_1/(52) if sp011_1==4;

gen hours_care2=sp012_2*7 if sp011_2==1;
replace hours_care2=sp012_2 if sp011_2==2;
replace hours_care2=sp012_2/(52/12) if sp011_2==3;
replace hours_care2=sp012_2/(52) if sp011_2==4;

gen hours_care3=sp012_3*7 if sp011_3==1;
replace hours_care3=sp012_3 if sp011_3==2;
replace hours_care3=sp012_3/(52/12) if sp011_3==3;
replace hours_care3=sp012_3/(52) if sp011_3==4;

gen h_c1=hours_care1 if (sp009_1==2 | sp009_1==3) & (sp011_1==1 | sp011_1==2);
replace h_c1=0 if h_c1==.;
gen h_c2=hours_care2 if (sp009_2==2 | sp009_2==3) & (sp011_2==1 | sp011_2==2);
replace h_c2=0 if h_c2==.;
gen h_c3=hours_care3 if (sp009_3==2 | sp009_3==3) & (sp011_3==1 | sp011_3==2);
replace h_c3=0 if h_c3==.;


tab group wave if gender==2;
tab sp012_1 if gender==2 & (sp009_1==2 | sp009_1==3) & (sp011_1==1 | sp011_1==2);
tab sp012_2 if gender==2 & (sp009_2==2 | sp009_2==3) & (sp011_2==1 | sp011_2==2);
tab sp012_3 if gender==2 & (sp009_3==2 | sp009_3==3) & (sp011_3==1 | sp011_3==2);

gen h_c=h_c1+h_c2+h_c3;

gen hw=ep013b if wave==2;
tab ep013_ if gender==2 & worker==1 & wave==2;

**We drop retired and permanently disabled people;
drop if (ep005_==4 | ep005_==1) & wave==2;
drop mwave;
egen mwave=sum(wave), by (mergeid1);
sort mergeid1 wave;
drop if mwave!=3;

**We keep the sample of longitudinals in wave 2;
keep if wave==2;



tab worker1 group if wave==2 & gender==2, col;
tab worker2 group if wave==2 & gender==2, col;
tab carerp group if wave==2 & gender==2, col;
tab carerpo group if wave==2 & gender==2 & carerp==1, col;
tab atweek1 group if wave==2 & gender==2 & carerp==1, col;
tab daily group if wave==2 & gender==2 & carerp==1 & atweek1==1, col;
tab atweek1 group if wave==2 & gender==2 & carerpo==1 & carerpi==0, col;
tab daily group if wave==2 & gender==2 & carerpo==1 & carerpi==0 & atweek1==1, col;


sum hw if gender==2 & wave==2 & worker==1 & group==1, det;
sum hw if gender==2 & wave==2 & worker==1 & group==2, det;
sum hw if gender==2 & wave==2 & worker==1 & group==3, det;



sum h_c if gender==2 & wave==2 & atweek1==1 & group==1, det;
sum h_c if gender==2 & wave==2 & atweek1==1 & group==2, det;
sum h_c if gender==2 & wave==2 & atweek1==1 & group==3, det;


sum h_c if gender==2 & wave==2 & atweek1==1 & carerpi==0 & group==1, det;
sum h_c if gender==2 & wave==2 & atweek1==1 & carerpi==0 & group==2, det;
sum h_c if gender==2 & wave==2 & atweek1==1 & carerpi==0 & group==3, det;


sum h_c if gender==2 & wave==2 & daily==1 & carerpi==0 & group==1, det;
sum h_c if gender==2 & wave==2 & daily==1 & carerpi==0 & group==2, det;
sum h_c if gender==2 & wave==2 & daily==1 & carerpi==0 & group==3, det;


sum h_c if gender==2 & wave==2 & daily==0 & carerpi==0 & atweek1==1 & group==1, det;
sum h_c if gender==2 & wave==2 & daily==0 & carerpi==0 & atweek1==1  & group==2, det;
sum h_c if gender==2 & wave==2 & daily==0 & carerpi==0 & atweek1==1  & group==3, det;


gen resident=(dn030_1==1 | dn030_2==1 );
replace resident=1 if wave==2 & dn026_1==. & ((cvid==1 & relrpers2==5 & ppgender==2) | (cvid==2 & relrpers2==6 & ppgender==2)
| (cvid==1 & relrpers2b==5 & ppgender2==2) | (cvid==2 & relrpers2b==6  & ppgender2==2));
replace resident=1 if wave==2 & dn026_2==. & ((cvid==1 & relrpers2==5 & ppgender==1) | (cvid==2 & relrpers2==6 & ppgender==1)
| (cvid==1 & relrpers2b==5 & ppgender2==1) | (cvid==2 & relrpers2b==6  & ppgender2==1)); 


gen resident1=(dn030_1<=4 | dn030_2<=4 | resident==1);
gen resident2=((dn030_1<=4 & dn030_1>=2) | (dn030_2<=4 & dn030_2>=2));




**RESULTS;		
**Results Table 4 (top panel): Longitudinal sample, no controls, Wald estimate;
**Caregiving effect (denominator);
forvalues c=1(1)3{;
          display "group==`c' gender1==2";
         reg daily ivphealth if  wave==2 & group==`c' & gender1==2, rob;          
				 };
**Employment effect (numerator);
forvalues c=1(1)3{;
          display "group==`c' gender1==2";
         reg worker1 ivphealth if  wave==2 & group==`c' & gender1==2, rob;
				 };




**This is the dummy of education that we use in the regressions;
gen educ=(educ1==1 | educ2==1);


**Results Table 4 (bottom panel): Longitudinal sample, with controls, biprobit;
**Including lworker1 as a control;
**We compute the numerator and denominator for LATE using the bivariate Probit (based on decision rules without exclusion restriction);
biprobit (worker1=ivphealth age1 educ sisters lworker1) (daily=ivphealth age1 educ sisters lworker1) if group==3, rob;

predict xbhat, xb1;
predict xghat, xb2;
matrix coef=e(b);
svmat coef, name(b);
replace b1=b1[_n-1] in 2/l;
replace b2=b2[_n-1] in 2/l;
replace b3=b3[_n-1] in 2/l;
replace b6=b6[_n-1] in 2/l;
replace b8=b8[_n-1] in 2/l;
replace b9=b9[_n-1] in 2/l;
replace b10=b10[_n-1] in 2/l;
replace b11=b11[_n-1] in 2/l;
replace b7=b7[_n-1] in 2/l;

gen x1b=xbhat-b1*ivphealth+b1 if group==3;
gen x2b=xbhat-b1*ivphealth if group==3;
gen x1g=xghat-b7*ivphealth+b7 if group==3;
gen x2g=xghat-b7*ivphealth if group==3;



gen df1b=normal(x1b) if group==3;
gen df2b=normal(x2b) if group==3;
gen df1g=normal(x1g) if group==3;
gen df2g=normal(x2g) if group==3;
gen num=df1b-df2b if group==3;
gen denom=df1g-df2g if group==3;
gen at=df2g if group==3;


drop b1-b13 xbhat xghat; 

biprobit (worker1=ivphealth age1 educ sisters lworker1) (daily= ivphealth age1 educ sisters lworker1) if group==2, rob;
predict xbhat, xb1;
predict xghat, xb2;
matrix coef=e(b);
svmat coef, name(b);
replace b1=b1[_n-1] in 2/l;
replace b2=b2[_n-1] in 2/l;
replace b3=b3[_n-1] in 2/l;
replace b6=b6[_n-1] in 2/l;
replace b8=b8[_n-1] in 2/l;
replace b9=b9[_n-1] in 2/l;
replace b10=b10[_n-1] in 2/l;
replace b11=b11[_n-1] in 2/l;
replace b7=b7[_n-1] in 2/l;
replace x1b=xbhat-b1*ivphealth+b1 if group==2;
replace x2b=xbhat-b1*ivphealth if group==2;
replace x1g=xghat-b7*ivphealth+b7 if group==2;
replace x2g=xghat-b7*ivphealth if group==2;


replace df1b=normal(x1b) if group==2;
replace df2b=normal(x2b) if group==2;
replace df1g=normal(x1g) if group==2;
replace df2g=normal(x2g) if group==2;
replace num=df1b-df2b if group==2;
replace denom=df1g-df2g if group==2;

drop b1-b13 xbhat xghat; 

biprobit (worker1=ivphealth age1 educ sisters lworker1) (daily=ivphealth age1 educ sisters lworker1) if group==1, rob;
predict xbhat, xb1;
predict xghat, xb2;
matrix coef=e(b);
svmat coef, name(b);
replace b1=b1[_n-1] in 2/l;
replace b2=b2[_n-1] in 2/l;
replace b3=b3[_n-1] in 2/l;
replace b6=b6[_n-1] in 2/l;
replace b7=b7[_n-1] in 2/l;
replace b8=b8[_n-1] in 2/l;
replace b9=b9[_n-1] in 2/l;
replace b10=b10[_n-1] in 2/l;
replace b11=b11[_n-1] in 2/l;
replace x1b=xbhat-b1*ivphealth+b1 if group==1;
replace x2b=xbhat-b1*ivphealth if group==1;
replace x1g=xghat-b7*ivphealth+b7 if group==1;
replace x2g=xghat-b7*ivphealth if group==1;


replace df1b=normal(x1b) if group==1;
replace df2b=normal(x2b) if group==1;
replace df1g=normal(x1g) if group==1;
replace df2g=normal(x2g) if group==1;
replace num=df1b-df2b if group==1;
replace denom=df1g-df2g if group==1; 

sort group;
egen numm=mean(num), by (group);
sort group;
egen denomm=mean(denom), by (group);
sort group;
gen latemb=numm/denomm;
tab numm group, col;
tab denomm group, col;
tab latemb group, col;

drop xbhat xghat x1b x2b x1g x2g df1b df1g df2b df2g num numm denom denomm latemb b1-b13;



**We generate the sample that we are using to compute the SEs of the estimators based on the longitudinal sample by group of countries; 
save `t1'sampleFRB_w1w2_ext_cross06_w2rel231_w1rel231_long, replace;
keep worker1 atweek1 daily ivphealth age1  group wave educ sisters gender lworker1;
keep if group==1 & wave==2 & gender==2;
save `t1'north_w1w2_2006_w2rel231_w1rel231_long, replace;
use `t1'sampleFRB_w1w2_ext_cross06_w2rel231_w1rel231_long;
keep worker1 atweek1 daily ivphealth age1  group wave educ sisters gender lworker1;
keep if group==2 & wave==2 & gender==2;
save `t1'cont_w1w2_2006_w2rel231_w1rel231_long, replace;
use `t1'sampleFRB_w1w2_ext_cross06_w2rel231_w1rel231_long;
keep worker1 atweek1 daily ivphealth age1  group wave educ sisters gender lworker1;
keep if group==3 & wave==2 & gender==2;
save `t1'sout_w1w2_2006_w2rel231_w1rel231_long, replace;


log close;
